﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Example03.aspx.cs" Inherits="Chapter28.Example03" %>

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>代码清单 28-3 使用 classList 属性</title>
    <meta name="author" content="Adam Freeman" />
    <meta name="description" content="A simple example" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
    <style>
        p {
            border: medium double black;
        }

            P.newClass {
                background-color: grey;
                color: white;
            }
    </style>
</head>
<body>
    <p id="textblock" class="fruit numbers">
        There are lots of different kinds of fruit - there are you over 500 varieties 
        of <span id="banana">banana</span> alone. By the time we add the countless 
        types of <span id="apple">apples</span>, 
       <span id="orange">oranges</span>, and other well-known fruit, we are 
        faced with thousands of choices.
    </p>
    <pre id="results"></pre>
    <button id="toggle">Toggle Class</button>
    <script>
        var results = document.getElementById("results");
        document.getElementById("toggle").onclick = toggleClass;

        listClasses();

        function listClasses() {
            var classlist = document.getElementById("textblock").classList;
            results.innerHTML = "Current classes: ";
            for (var i = 0; i < classlist.length; i++) {
                results.innerHTML += classlist[i] + " ";
            }
        }

        function toggleClass() {
            document.getElementById("textblock").classList.toggle("newClass");
            listClasses();
        }
    </script>
</body>
</html>
